package org.bit.lesson02;

public class Demo205 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程执行完成...");
        });

        System.out.println("启动之前查看线程存活状态" + thread.isAlive());
        // 启动线程
        thread.start();
        System.out.println("启动之后查看线程存活状态" + thread.isAlive());
        // 等待线程执行结束
        thread.join();
        // 保证PCB已经销毁
        Thread.sleep(1000);
        System.out.println("线程结束之后查看线程存活状态" + thread.isAlive());
    }

}
